﻿using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 约球用户报名
    /// </summary>
    public class BallUserJoinAddDto : IValidatableObject
    {
        /// <summary>
        /// 约球ID
        /// </summary>
        [Required]
        public Guid BallId { get; set; }

        /// <summary>
        /// 约球用户
        /// </summary>
        [Required]
        [MinLength(1)]
        public List<Guid> UserIdList { get; set; }

        /// <summary>
        /// 报名日期
        /// </summary>
        [Required]
        public DateTimeOffset JoinDate { get; set; } = DateTimeOffset.Now.Date;

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            JoinDate = JoinDate.Date;
            foreach (var item in UserIdList)
            {
                if (UserIdList.Count(m => m == item) >= 2)
                {
                    yield return new ValidationResult("报名用户重复");
                    yield break;
                }
            }
        }
    }
}
